package cool.tenyears.controller;

import cool.tenyears.core.domain.R;
import cool.tenyears.core.domain.RL;
import cool.tenyears.domain.User;
import cool.tenyears.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiChuan
 * @date 2021/6/17 19:15
 */
@RestController
@RequestMapping("/sys/user")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @GetMapping("/list")
    public RL<User> list(User user) {
        List<User> list = userService.list(user);
        return RL.list(list);
    }

    @GetMapping("/{userId}")
    public R<?> getUser(@PathVariable String userId) {
        return R.ok(userService.getById(userId));
    }

    @PostMapping()
    public R<?> add(User user) {
        return R.rep(userService.add(user));
    }
}
